using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ebcpatterns.flow;
using NUnit.Framework;

namespace ebcpatterns.tests.flow
{
    [TestFixture]
    public class ManualResetJoinTests
    {
        [Test]
        public void Do_a_regular_join_as_default()
        {
            var join = new ManualResetJoin<int, int, MyTuple<int, int>>();

            MyTuple<int, int> result = null;
            join.Output += x => result = x;
            join.Input1(1);
            join.Input2(2);
            join.Input2(3);

            Assert.That(result.Item1, Is.EqualTo(1));
            Assert.That(result.Item2, Is.EqualTo(3));
        }


        [Test]
        public void Wait_for_pairing_input_after_reset()
        {
            var join = new ManualResetJoin<int, int, MyTuple<int, int>>();

            MyTuple<int, int> result = null;
            join.Output += x => result = x;
            join.Input1(1);
            join.Input2(2);

            join.Reset();

            join.Input2(3);
            Assert.That(result.Item1, Is.EqualTo(1));
            Assert.That(result.Item2, Is.EqualTo(2));

            join.Input1(4);
            Assert.That(result.Item1, Is.EqualTo(4));
            Assert.That(result.Item2, Is.EqualTo(3));
        }
    }
}